package com.codegeek.project.slope.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.slope.domain.SlopeNvr;
import com.codegeek.project.slope.service.ISlopeNvrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * nvrController
 *
 * @author codegeek
 * @date 2020-02-17
 */
@RestController
@RequestMapping("/slope/nvr")
@Api(value = "nvrController", tags = {"nvr操作接口"})
public class SlopeNvrController extends BaseController {
    @Autowired
    private ISlopeNvrService slopeNvrService;

    /**
     * 查询nvr列表
     */
    @ApiOperation("查询nvr列表")
    @GetMapping("/list")
    public TableDataInfo list(SlopeNvr slopeNvr) {
        startPage();
        List<SlopeNvr> list = slopeNvrService.selectSlopeNvrList(slopeNvr);
        return getDataTable(list);
    }

    /**
     * 导出nvr列表
     */
    @ApiOperation("导出nvr列表")
    @Log(title = "nvr", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SlopeNvr slopeNvr) {
        List<SlopeNvr> list = slopeNvrService.selectSlopeNvrList(slopeNvr);
        ExcelUtil<SlopeNvr> util = new ExcelUtil<SlopeNvr>(SlopeNvr.class);
        return util.exportExcel(list, "nvr");
    }

    /**
     * 获取nvr详细信息
     */
    @ApiOperation("获取nvr详细信息")
    @GetMapping(value = "/getInfo/{nvrId}")
    public AjaxResult getInfo(@PathVariable("nvrId") Long nvrId) {
        return AjaxResult.success(slopeNvrService.selectSlopeNvrById(nvrId));
    }

    /**
     * 新增nvr
     */
    @ApiOperation("新增nvr")
    @Log(title = "nvr", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SlopeNvr slopeNvr) {
        return toAjax(slopeNvrService.insertSlopeNvr(slopeNvr));
    }

    /**
     * 修改nvr
     */
    @ApiOperation("修改nvr")
    @Log(title = "nvr", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SlopeNvr slopeNvr) {
        return toAjax(slopeNvrService.updateSlopeNvr(slopeNvr));
    }

    /**
     * 删除nvr
     */
    @ApiOperation("删除nvr")
    @Log(title = "nvr", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{nvrIds}")
    public AjaxResult remove(@PathVariable Long[] nvrIds) {
        return toAjax(slopeNvrService.deleteSlopeNvrByIds(nvrIds));
    }
}
